package cn.xgj.sfzy.controller;

import cn.xgj.sfzy.entity.ArticleType;
import cn.xgj.sfzy.entity.MyAssessment;
import cn.xgj.sfzy.entity.UserAssessment;
import cn.xgj.sfzy.service.UserAssessmentService;
import cn.xgj.sfzy.util.Result;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @ClassName UserAssessmentController
 * @Description TODO
 * @Author furuyue
 * @Date 2024年10月24日 11:51
 * @Version 1.0
 */

@RestController
@RequestMapping("/userAssessment")
public class UserAssessmentController {

    @Autowired
    private UserAssessmentService userAssessmentService;

    @RequestMapping("/findAll")
    public Result findAll(UserAssessment UserAssessment){
        List<UserAssessment> list = userAssessmentService.findAll(UserAssessment);
        return Result.success(list);
    }
    @RequestMapping("/findByPage")
    public Result findByPage(
            @RequestParam(required = false,defaultValue = "1") Integer pageNum,
            @RequestParam(required = false,defaultValue = "2") Integer pageSize,
            UserAssessment UserAssessment){
        PageInfo<UserAssessment> byPage = userAssessmentService.findByPage(pageNum, pageSize, UserAssessment);
        return Result.success(byPage);
    }

    @DeleteMapping("/{UserAssessmentId}")
    public Result delete(@PathVariable(value = "UserAssessmentId") Integer UserAssessmentId){
        int num = userAssessmentService.remove(UserAssessmentId);
        if(num!=0){
            return Result.success("删除成功");
        }else{
            return Result.error("删除失败");
        }
    }

    @RequestMapping("/findByAppointmentId")
    public Result findByAppointmentId(Long appointmentId){
        List<UserAssessment> list = userAssessmentService.findByAppointmentId(appointmentId);
        return Result.success(list);
    }

    @PostMapping("/add")
    public Result add(@RequestBody UserAssessment userAssessment){
        int add = userAssessmentService.add(userAssessment);
        if (add==0){
            return Result.error("添加失败");
        }else {
            return Result.success("添加成功");
        }
    }

    @PutMapping
    public Result update(@RequestBody UserAssessment userAssessment){
        int num = userAssessmentService.edit(userAssessment);
        if (num==0){
            return Result.error("修改失败");
        }else {
            return Result.success("修改成功");
        }

    }
}
